<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function isAdditiveNumber(num) {
      const n = num.length;
      for (let i = 2; i < n; i++) {
        const subStr = num.substr(0, i);

        starting: for (let j = 1; j < i; j++) {
          let A = subStr.substr(0, j);
          let B = subStr.substr(j, i - j);
          if (A[0] === "0" && A.length > 1 || B[0] === "0" && B.length > 1)
            continue;
          A = parseInt(A);
          B = parseInt(B);

          //上面这两层循环-----------------主要穷举两个起始数A B, 和C的起始点
          let start = i;
          let tempA = A;
          let tempB = B;
          while (start < n) {
            const AplusB = tempA + tempB;
            const tempC = parseInt(num.substr(start, AplusB.toString().length));
            // console.log(`A=${tempA},B=${tempB},C=${tempC},A+B=${AplusB},${AplusB === tempC}`);
            if (AplusB === tempC) {
              tempA = tempB;
              tempB = tempC;
              start += AplusB.toString().length;
              continue;
            } else {
              // initLen += 1;
              continue starting;
            }
          }
          return true;
        }

      }
      return false
    };
    console.log(isAdditiveNumber("112358"))
  </script>
</body>

</html>